<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" :title="发货" width="500px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
      <el-form-item label="物流公司" prop="shippingWay">
        <el-input v-model="form.shippingWay" style="width: 360px;"/>
      </el-form-item>
      <el-form-item label="物流编号" prop="shippingNo">
        <el-input v-model="form.shippingNo" style="width: 360px;"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认发货</el-button>
    </div>
  </el-dialog>
</template>

<script>
// import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
export default {
  // components: { Treeselect },
  props: {
    sup_this: {
      type: Object,
      default: null
    }
  },
  inject: ['Edit'],
  data() {
    return {
      loading: false, dialog: false,
      form: { shippingNo: '', shippingWay: ''},
      orderNo:"",
      shippingNo: "",
      shippingWay: "",
      rules: {
        shippingNo: [
          { required: true, message: '请输入物流单号', trigger: 'blur' }
        ],
        shippingWay: [
          { required: true, message: '请输入物流公司', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    doSubmit() {
       let formData = Object.assign({}, this.form, { orderNo: this.orderNo })
      this.$api.fenxiao.order.sendGoods({
        data: formData
      }).then(res => {
        this.resetForm()
        this.$notify({
          title: '添加成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    updateOrderNo(orderNo) {
       this.orderNo = orderNo
    },
    resetForm() {
      this.dialog = false
      this.$refs['form'].resetFields()
      this.form = { shippingNo: '', shippingWay: ''}
    }
  }
}
</script>
<style scoped>
</style>
